package thread;

public class SyncDemo5 {
    public static void main(String[] args) {
        Coo coo = new Coo();
        Thread t1 = new Thread(coo::aoo);
        Thread t2 = new Thread(coo::boo);
        Thread t3 = new Thread(coo::eoo);
        t1.start();
        t2.start();
        t3.start();

    }
}
class Coo{
    public  synchronized void aoo(){
        try {
            System.out.println("开始吃饭");
            Thread.sleep(3000);
            System.out.println("吃完了,结账");
        } catch (InterruptedException e) {
        }
    }

    public synchronized void boo(){
        try {
            System.out.println("开始吃饭");
            Thread.sleep(3000);
            System.out.println("吃完了,结账");
        } catch (InterruptedException e) {
        }
    }
    public  void eoo(){
        synchronized (this){
            try {
                System.out.println("开始吃饭");
                Thread.sleep(3000);
                System.out.println("吃完了,结账");
            } catch (InterruptedException e) {
            }
        }

    }
}
